package com.youthburin.rmp.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.youthburin.base.util.DwzPagination;
import com.youthburin.rmp.enums.RmpOpLogBusiTypeEnum;
import com.youthburin.rmp.enums.RmpOpLogTypeEnum;
import com.youthburin.rmp.services.RmpOpLogService;

@Controller
public class RmpOpLogController {
	@Autowired
	@Qualifier("rmpOpLogService")
	private RmpOpLogService rmpOpLogService;

	@RequiresPermissions("oplog:list")
	@RequestMapping(value = "/system/oplog/list")
	public String list(HttpServletRequest request) {
		rmpOpLogService.addLog(RmpOpLogTypeEnum.LIST.toString(), RmpOpLogBusiTypeEnum.RMP_OP_LOG.toString());
		rmpOpLogService.dwzFindAll((DwzPagination) request.getAttribute(DwzPagination.DWZPAGINATION_PROPERTY_KEY));
		return "system/oplog/list";
	}

	@RequiresPermissions("oplog:view")
	@RequestMapping(value = "/system/oplog/view/{logId}", method = RequestMethod.GET)
	public String toView(@PathVariable("logId") String logId, ModelMap model) {
		model.put("opLog", rmpOpLogService.get(logId));
		model.put("readOnly", "1");

		return "system/oplog/edit";
	}
}
